﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using MySql.Data.MySqlClient;

public class DAL_tbl_siconide_milljet
{
    public DAL_tbl_siconide_milljet()
    {

    }



    public List<tbl_siconide_milljet> select(int ID)
    {
        List<tbl_siconide_milljet> list = new List<tbl_siconide_milljet>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Mill,Feed_Rate,Charge_Number,Pressure,Flowbin_Number,Quantity_Used_MJ1,SSA,Remark,Previous_Process,PALLA_RUN_NUMBER,MILLJET_RUN_NUMBER,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_milljet where ID=@ID";
        cmd.Parameters.AddWithValue("@ID", ID);
        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_milljet()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Mill = Convert.ToInt32(dr["Mill"]),
                Feed_Rate = Convert.ToDecimal(dr["Feed_Rate"]),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Pressure = Convert.ToDecimal(dr["Pressure"]),
                Flowbin_Number = Convert.ToDecimal(dr["Flowbin_Number"]),
                Quantity_Used_MJ1 = Convert.ToDecimal(dr["Quantity_Used_MJ1"]),
                SSA = Convert.ToDecimal(dr["SSA"]),
                Remark = dr["Remark"].ToString(),
                Previous_Process = dr["Previous_Process"].ToString(),
                PALLA_RUN_NUMBER = dr["PALLA_RUN_NUMBER"].ToString(),
                MILLJET_RUN_NUMBER = dr["MILLJET_RUN_NUMBER"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }



    public List<tbl_siconide_milljet> selectAll()
    {
        List<tbl_siconide_milljet> list = new List<tbl_siconide_milljet>();
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = "Select ID,Mill,Feed_Rate,Charge_Number,Pressure,Flowbin_Number,Quantity_Used_MJ1,SSA,Remark,Previous_Process,PALLA_RUN_NUMBER,MILLJET_RUN_NUMBER,IS_ACTIVE,CREATED_BY,CREATED_DATE,UPDATED_BY,UPDATED_DATE from tbl_siconide_milljet Order By ID";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        foreach (DataRow dr in dt.Rows)
        {
            list.Add(new tbl_siconide_milljet()
            {
                ID = Convert.ToInt32(dr["ID"]),
                Mill = Convert.ToInt32(dr["Mill"]),
                Feed_Rate = Convert.ToDecimal(dr["Feed_Rate"]),
                Charge_Number = Convert.ToDecimal(dr["Charge_Number"]),
                Pressure = Convert.ToDecimal(dr["Pressure"]),
                Flowbin_Number = Convert.ToDecimal(dr["Flowbin_Number"]),
                Quantity_Used_MJ1 = Convert.ToDecimal(dr["Quantity_Used_MJ1"]),
                SSA = Convert.ToDecimal(dr["SSA"]),
                Remark = dr["Remark"].ToString(),
                Previous_Process = dr["Previous_Process"].ToString(),
                PALLA_RUN_NUMBER = dr["PALLA_RUN_NUMBER"].ToString(),
                MILLJET_RUN_NUMBER = dr["MILLJET_RUN_NUMBER"].ToString(),
                IS_ACTIVE = Convert.ToBoolean(dr["IS_ACTIVE"]),
                CREATED_BY = dr["CREATED_BY"].ToString(),
                CREATED_DATE = dr["CREATED_DATE"].toDateTimeWithoutError(),
                UPDATED_BY = dr["UPDATED_BY"].ToString(),
                UPDATED_DATE = dr["UPDATED_DATE"].toDateTimeWithoutError()
            });
        }

        return list;
    }

    public DataTable selectAllForGrid()
    {
        MySqlCommand cmd = new MySqlCommand();
        cmd.CommandText = @"Select sm.ID,mm.SHORT_NAME as Mill,sm.Feed_Rate,sm.Charge_Number,sm.Pressure,sm.Flowbin_Number,sm.Quantity_Used_MJ1,sm.SSA,sm.Remark,sm.Previous_Process,sm.PALLA_RUN_NUMBER,sm.MILLJET_RUN_NUMBER,CASE WHEN sm.IS_ACTIVE =1 THEN 'True' ELSE 'False' END as 'IS_ACTIVE',
sm.CREATED_BY,sm.CREATED_DATE as CREATED_DATE,sm.UPDATED_BY,
sm.UPDATED_DATE as UPDATED_DATE 
from tbl_siconide_milljet sm LEFT JOIN tbl_mills_master mm on mm.MILL_ID=sm.Mill Order By sm.ID desc";

        DataTable dt = DBUtil.ExecuteDataTable(cmd);
        return dt;
    }

    public int insert(int Mill, Decimal Feed_Rate, Decimal Charge_Number, Decimal Pressure, Decimal Flowbin_Number, Decimal Quantity_Used_MJ1, Decimal SSA, String Remark, String Previous_Process, String PALLA_RUN_NUMBER, String MILLJET_RUN_NUMBER, String CREATED_BY, DateTime CREATED_DATE)
    {
        int i = 0;
        string sql = @"Insert into tbl_siconide_milljet(Mill,Feed_Rate, Charge_Number, Pressure, Flowbin_Number, Quantity_Used_MJ1, SSA, Remark,Previous_Process, PALLA_RUN_NUMBER, MILLJET_RUN_NUMBER, CREATED_BY, CREATED_DATE)
                        values(@Mill,@Feed_Rate, @Charge_Number, @Pressure, @Flowbin_Number, @Quantity_Used_MJ1, @SSA, @Remark, @Previous_Process, @PALLA_RUN_NUMBER, @MILLJET_RUN_NUMBER, @CREATED_BY, @CREATED_DATE)";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("Mill", Mill);
        cmd.Parameters.AddWithValue("@Feed_Rate", Feed_Rate);
        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Pressure", Pressure);
        cmd.Parameters.AddWithValue("@Flowbin_Number", Flowbin_Number);
        cmd.Parameters.AddWithValue("@Quantity_Used_MJ1", Quantity_Used_MJ1);
        cmd.Parameters.AddWithValue("@SSA", SSA);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@Previous_Process", Previous_Process);
        cmd.Parameters.AddWithValue("@PALLA_RUN_NUMBER", PALLA_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@MILLJET_RUN_NUMBER", MILLJET_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@CREATED_BY", CREATED_BY);
        cmd.Parameters.AddWithValue("@CREATED_DATE", CREATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int update(int ID, int Mill, Decimal Feed_Rate, Decimal Charge_Number, Decimal Pressure, Decimal Flowbin_Number, Decimal Quantity_Used_MJ1, Decimal SSA, String Remark, String Previous_Process, String PALLA_RUN_NUMBER, String MILLJET_RUN_NUMBER, String UPDATED_BY, DateTime UPDATED_DATE)
    {
        int i = 0;
        string sql = @"Update tbl_siconide_milljet SET Mill=@Mill, Feed_Rate=@Feed_Rate, Charge_Number=@Charge_Number, Pressure=@Pressure, Flowbin_Number=@Flowbin_Number, Quantity_Used_MJ1=@Quantity_Used_MJ1, SSA=@SSA, Remark=@Remark, Previous_Process=@Previous_Process, PALLA_RUN_NUMBER=@PALLA_RUN_NUMBER, MILLJET_RUN_NUMBER=@MILLJET_RUN_NUMBER, UPDATED_BY=@UPDATED_BY, UPDATED_DATE=@UPDATED_DATE WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);
        cmd.Parameters.AddWithValue("Mill", Mill);
        cmd.Parameters.AddWithValue("@Feed_Rate", Feed_Rate);
        cmd.Parameters.AddWithValue("@Charge_Number", Charge_Number);
        cmd.Parameters.AddWithValue("@Pressure", Pressure);
        cmd.Parameters.AddWithValue("@Flowbin_Number", Flowbin_Number);
        cmd.Parameters.AddWithValue("@Quantity_Used_MJ1", Quantity_Used_MJ1);
        cmd.Parameters.AddWithValue("@SSA", SSA);
        cmd.Parameters.AddWithValue("@Remark", Remark);
        cmd.Parameters.AddWithValue("@Previous_Process", Previous_Process);
        cmd.Parameters.AddWithValue("@PALLA_RUN_NUMBER", PALLA_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@MILLJET_RUN_NUMBER", MILLJET_RUN_NUMBER);
        cmd.Parameters.AddWithValue("@UPDATED_BY", UPDATED_BY);
        cmd.Parameters.AddWithValue("@UPDATED_DATE", UPDATED_DATE);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }



    public int delete(int ID)
    {
        int i = 0;
        string sql = "Delete FROM tbl_siconide_milljet WHERE ID=@ID";

        MySqlCommand cmd = new MySqlCommand(sql);

        cmd.Parameters.AddWithValue("@ID", ID);

        i = DBUtil.ExecuteNonQuery(cmd);
        return i;
    }

    public DataTable GetPalla_Run_Number()
    {
        DataTable dt = new DataTable();
        try
        {
            MySqlCommand cmd = new MySqlCommand();
            cmd.CommandText = "SELECT ID,PALLA_RUN_NUMBER FROM tbl_siconide_palla where IS_ACTIVE=1";
            dt = DBUtil.ExecuteDataTable(cmd);
            return dt;
        }
        catch (Exception)
        {

            throw;
        }
        finally { dt = null; }

    }

}